﻿using StoneAge.Controller.Request;
using StoneAge.Controller.Storage;
using StoneAge.DataContract.Messaging;

namespace StoneAge.Controller.Handlers
{
    abstract class PostResponseRequestHandler : RequestHandler
    {
        public PostResponseRequestHandler(string route) : base(route) { }

        public override void Handle(WebRequest webRequest)
        {
            if (Route.Matches(webRequest))
            {
                ResponseBase response = GetResponseBy(webRequest);
                Storage.Add(HttpStorageKeys.Data, response);
                webRequest.AsyncResult.SetCompleted();
            }
            else
            {
                NextHandler.Handle(webRequest);
            }
        }

        protected abstract ResponseBase GetResponseBy(WebRequest webRequest);
    }
}
